// pages/center/order/order.js
var util = require("../../../utils/util.js");

Page({

  /**
   * 页面的初始数据
   */
  data: {
    OrderList:[
      {
        Pay_OrderType:0,
        OrderState:0,
        CoverImageUrl:"../../resource/image/0002.gif",
        Title:"全新课程首付都打发时间哦封建士大夫精神的飞机啊了塑料袋放进哦是多久哦副教授地方圣诞节佛山警方",
        Price:"2.00"
      },
      {
        Pay_OrderType: 1,
        OrderState: 0,
        CoverImageUrl: "../../resource/image/0001.gif",
        Title: "最新视频",
        Price: "3.00"
      },
      {
        Pay_OrderType: 2,
        OrderState: 0,
        CoverImageUrl: "../../resource/image/0003.gif",
        Title: "教你唱歌",
        Price: "0.01"
      },
      {
        Pay_OrderType: 10,
        OrderState: 3,
        CoverImageUrl: "../../resource/image/0004.gif",
        Title: "教你画画",
        Price: "0.02"
      },
      {
        Pay_OrderType: 11,
        OrderState: 0,
        CoverImageUrl: "../../resource/image/0005.gif",
        Title: "往期精选",
        Price: "0.03"
      },
      {
        Pay_OrderType: 20,
        OrderState: 3,
        CoverImageUrl: "../../resource/image/0006.gif",
        Title: "教你如何画彩色",
        Price: "0.05"
      }
    ]
  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var UserID = getApp().globalData.userId; 
    var params = {
      Param:{
        UserID: UserID ,
        PageIndex:1,
        ShowIndexNum:50,
        SearchKey:""
      },
      Action:570
    };
    var page = this;
    util.reqMedia(params,function(value){
      console.log(value);
        page.setData({
          OrderList: value.OrderList
        });
    });
  
  },
  onPay:function(e){
    var UserID = e.target.dataset.id;
    var xy_OutTradeNo = e.target.dataset.userid;
    var title = e.target.dataset.title;
    var detail = {
      ID: xy_OutTradeNo,
      Title:title
    };
    var params ={
        Param:{
          UserID: UserID,
          xy_OutTradeNo: xy_OutTradeNo,
          ModeOfPayment:1
        },
      Action:520
    };
    util.reqMedia(params, function (value) {
      wx.requestPayment({
        timeStamp: value.timestamp,
        nonceStr: value.noncestr,
        package: 'prepay_id=' + value.prepayid,
        signType: 'MD5',
        paySign: value.sign,
        success: function (res) {
          wx.navigateTo({
            url: '/pages/afterPay/afterPay?detail='+JSON.stringify(detail) ,
          });
        }
      });
    });

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})